package com.x.linx.fenfencard.model;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import com.baidu.platform.comapi.map.d;
import com.x.linx.fenfencard.model.meta.IRequestCallback;
import com.x.linx.fenfencard.model.meta.Location;
import com.x.linx.fenfencard.model.meta.ReturnSignIn;
import com.x.linx.utils.D;

import android.content.Context;

@EBean
public class Manager {
	@RootContext
	Context context;
	@Bean
	User user;
	@Bean
	Organize organize;

	// + function
	public void signin(final IRequestCallback callback) {
		signin(user.getUsername(), user.getPassword(), callback);
	}

	public void signin(final String username, final String password,
			final IRequestCallback callback) {
		user.signin(username, password, new IRequestCallback() {
			@Override
			public void success(Object returnValueObject) {
				ReturnSignIn ret = (ReturnSignIn) returnValueObject;
				user.setUsername(username);
				user.setPassword(password);
				D.i("ret=" + ret);
				D.i("ret.getContent()=" + ret.getContent());
				user.setToken(ret.getContent().getToken());
				callback.success(returnValueObject);
			}
			@Override
			public void fail(String errorMessage) {
				callback.fail(errorMessage);
			}
		});
	}

	public void getMoreOrgList(Location location, final int limit,
			final IRequestCallback callback) {
		organize.getMoreOrgList(location, limit, callback);
	}

	// - function

	// + set & get
	public User getUser() {
		return user;
	}

	public Organize getOrganize() {
		return organize;
	}
	// - set & get

}
